//
//  THCPCHomeVC.m
//  YJB
//
//  Created by YJB on 2016/11/26.
//  Copyright © 2016年 YJB. All rights reserved.
//

#import "THCPCHomeVC.h"
#import "THCustomTabBar.h"
#import "masonry.h"
#import "THCPCHallVC.h"
#import "THMyPublishVC.h"
#import "THMyJoinVC.h"
#import "THCPCSearchVC.h"
#import "THCpcTaskPublishVC.h"
#import "THCPCPublishNewVC.h"

@interface THCPCHomeVC ()
@property(nonatomic,weak)UIView *currentShowView;

@end

@implementation THCPCHomeVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kUIColorFromRGB(0xffebe7);
    self.title = @"CPC赚钱";
    
    [self setupNav];
    
    THCustomTabBar *customTabBar = [[THCustomTabBar alloc]init];
    [self.view addSubview:customTabBar];
    YJWeakSelf
    customTabBar.tabBarItemClickBlock = ^(THCustomTabBarItemType type){
        [weakSelf tabBarItemClick:type];
    };
    [customTabBar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(49);
    }];
    
    //任务大厅
    THCPCHallVC *cpcHallVC = [[THCPCHallVC alloc]init];
    [self addChildViewController:cpcHallVC];
    cpcHallVC.view.x = 0;
    cpcHallVC.view.y = 0;
    cpcHallVC.view.width = self.view.width;
    cpcHallVC.view.height = IPHONE_H - 49;
    [self.view addSubview:cpcHallVC.view];
    self.currentShowView = cpcHallVC.view;
    //我发布的
    THMyPublishVC *myPublishVC = [[THMyPublishVC alloc]init];
    [self addChildViewController:myPublishVC];
    //我参与的
    THMyJoinVC *myJoinVC = [[THMyJoinVC alloc]init];
    [self addChildViewController:myJoinVC];

}

- (void)searchBtnClick
{
    [self.navigationController pushViewController:[[THCPCSearchVC alloc] init] animated:YES];
}

- (void)addTask
{
//    [self.navigationController pushViewController:[[THCpcTaskPublishVC alloc] init] animated:YES];
    THCPCPublishNewVC *pub = [[THCPCPublishNewVC alloc] init];
    [self.navigationController pushViewController:pub animated:YES];
}

- (void)setupNav
{
    self.title = @"任务列表";
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.tintColor = NAVTITLECOLOR;
    UIBarButtonItem *searchBtn = [UIBarButtonItem itemWithTarget:self action:@selector(searchBtnClick) image:@"th_search_white" highImage:@"th_search_gary" width:25 imageOffset:8];
    UIBarButtonItem *choiceBtn = [UIBarButtonItem itemWithTarget:self action:@selector(addTask) image:@"th_add_task" highImage:nil width:25 imageOffset:8];
    self.navigationItem.rightBarButtonItems = @[choiceBtn,searchBtn];
    
}


- (void)tabBarItemClick:(THCustomTabBarItemType)type
{
    [self.currentShowView removeFromSuperview];
    UIViewController *currentVC = nil;
    switch (type)
    {
        case THCustomTabBarItemTypeHall:
            currentVC = self.childViewControllers[0];
            break;
        case THCustomTabBarItemTypeMyPublish:
            currentVC = self.childViewControllers[1];
            break;
        case THCustomTabBarItemTypeMyJoin:
            currentVC = self.childViewControllers[2];
            break;
    }
    currentVC.view.x = 0;
    currentVC.view.y = 0;
    currentVC.view.width = self.view.width;
    currentVC.view.height = IPHONE_H - 49 - 64;
    [self.view addSubview:currentVC.view];
    self.currentShowView = currentVC.view;
}


@end
